package com.filesystem.file.controller;


import com.filesystem.file.entity.User;
import com.filesystem.file.service.impl.UserServiceImpl;
import com.filesystem.utils.Result;
//import com.filesystem.utils.ResultUtil;
import com.filesystem.utils.ResultUtil;
import com.filesystem.utils.Results;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JayZhou
 * @since 2021-06-10
 */
@RestController
@RequestMapping("/file/user")
public class UserController {


    @Autowired
    HttpServletRequest request;
    @Autowired
    UserServiceImpl userService;

    @PostMapping("/login")
    public Results login(@RequestParam("username") String username , @RequestParam("password") String password){
        //获取UserRealm验证方法
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        Subject currentUser = SecurityUtils.getSubject();
        try {
            currentUser.login(token);
        }catch ( AuthenticationException e){
            return ResultUtil.error(1,"账号密码错误");
        }
        return  ResultUtil.success();
    }

   public Results  getAllUser(){
       return ResultUtil.success();
   }


}
